package com.dongdongshop.mq;

import com.dongdongshop.service.ItemPageServiceI;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
// 配置消费者监听的topic和消费者的组
@RocketMQMessageListener(topic = "dongdongshop-itempage",consumerGroup = "dongdongshop")
public class ItemPageMq implements RocketMQListener<Long[]> {

    @Resource
    private ItemPageServiceI itemPageServiceI;
    @Override
    public void onMessage(Long[] ids) {
       try {
           for (Long id : ids) {
               itemPageServiceI.showItemPage(id);
               System.out.println("消费成功");
           }
       }catch (Exception e){
           System.out.println("消费失败");
       }
    }
}
